/*
 * Sale.cpp
 *   Implementation for the class Sale.
 *   The interface for the class Sale is in the file Sale.h.
 *
 *  Created on: Mar 1, 2014
 *      Author: Anthony Varghese - This is from the Savitch book
 */

#include "Sale.h"
#include <iostream>
#include <cstdlib>

namespace SavitchSale {

Sale::Sale( ) : price(0) {
    //Intentionally empty
}

Sale::Sale(double thePrice) {
    if (thePrice >= 0)
        price = thePrice;
    else    {
        std::cout << "Error: Cannot have a negative price!\n";
        exit(1);
    }
}

double Sale::bill( ) const {
    return price;
}

double Sale::getPrice( ) const {
    return price;
}

void Sale::setPrice(double newPrice) {
    if (newPrice >= 0)
        price = newPrice;
    else {
    	std::cout << "Error: Cannot have a negative price!\n";
        exit(1);
    }
}

double Sale::savings(const Sale& other) const {
    return (bill( ) - other.bill( ));
}

bool operator < (const Sale& first, const Sale& second) {
    return (first.bill( ) < second.bill( ));
}

} /* namespace SavitchSale */
